﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DinhMuc.Public;

namespace DinhMuc.DAL
{
    public class tblDonHangDAL
    {
        clsConnect cn = new clsConnect();
        public DataTable bangDonHang()
        {
            return cn.LoadTableStore("sp_donhang_select");
        }
        public void import(string sql, tblDonHangPuclic p)
        {
            int para = 13;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@A";
            name[1] = "@B";
            name[2] = "@C";
            name[3] = "@D";
            name[4] = "@E";
            name[5] = "@F";
            name[6] = "@G";
            name[7] = "@H";
            name[8] = "@I";
            name[9] = "@J";
            name[10] = "@K";
            name[11] = "@L";
            name[12] = "@M";
            value[0] = p.soDH;
            value[1] = p.maSP;
            value[2] = p.maKH;
            value[3] = p.maTrucIn;
            value[4] = p.ngayLap;
            value[5] = p.nguoiPhuTrach;
            value[6] = p.DVT;
            value[7] = p.slDonHang;
            value[8] = p.tgGiaoHang;
            value[9] = p.khoMang;
            value[10] = p.DoDay;
            value[11] = p.ghiChu;
            value[12] = p.ketQua;
            cn.UpdateTable(sql, name, value, para);
        }
        public int ThemDH(tblDonHangPuclic p)
        {
            string sql = "sp_donhang_insert";
            int para = 12;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@soDH";
            name[1] = "@maSP";
            name[2] = "@maKH";
            name[3] = "@maTrucIn";
            name[4] = "@ngayLap";
            name[5] = "@nguoiPhuTrach";
            name[6] = "@DVT";
            name[7] = "@slDonHang";
            name[8] = "@tgGiaoHang";
            name[9] = "@khoMang";
            name[10] = "@doDay";
            name[11] = "@ghiChu";
            
            value[0] = p.soDH;
            value[1] = p.maSP;
            value[2] = p.maKH;
            value[3] = p.maTrucIn;
            value[4] = p.ngayLap;
            value[5] = p.nguoiPhuTrach;
            value[6] = p.DVT;
            value[7] = p.slDonHang;
            value[8] = p.tgGiaoHang;
            value[9] = p.khoMang;
            value[10] = p.DoDay;
            value[11] = p.ghiChu;
                    
            return cn.UpdateTableStore(sql, name, value, para);

        }
        public DataTable LoadToComBoBox_maSP()
        {
            DataTable dt= cn.LoadTableStore("sp_sanpham_select");
            return dt;
        }
        public DataTable LoadToComBoBox_maKH()
        {
            DataTable dt = cn.LoadTableStore("sp_khachhang_select");
            return dt;
        }
        public DataTable LoadToComBoBox_DVT()
        {
            DataTable dt = cn.LoadTableStore("sp_DVT_select");
            return dt;
        }
        public DataTable LoadToComBoBox_tienDo()
        {
            DataTable dt = cn.LoadTableStore("sp_tienDo_select");
            return dt;
        }
        public int suaDH(tblDonHangPuclic p)
        {
            int para = 13;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@soDH";
            name[1] = "@maSP";
            name[2] = "@maKH";
            name[3] = "@maTrucIn";
            name[4] = "@ngayLap";
            name[5] = "@nguoiPhuTrach";
            name[6] = "@DVT";
            name[7] = "@slDonHang";
            name[8] = "@tgGiaoHang";
            name[9] = "@khoMang";
            name[10] = "@doDay";
            name[11] = "@ghiChu";
            name[12] = "@ketQua";
            value[0] = p.soDH;
            value[1] = p.maSP;
            value[2] = p.maKH;
            value[3] = p.maTrucIn;
            value[4] = p.ngayLap;
            value[5] = p.nguoiPhuTrach;
            value[6] = p.DVT;
            value[7] = p.slDonHang;
            value[8] = p.tgGiaoHang;
            value[9] = p.khoMang;
            value[10] = p.DoDay;
            value[11] = p.ghiChu;
            value[12] = p.ketQua;
            return cn.UpdateTableStore("sp_donhang_Update", name, value, para);
        }
        public int xoaDH(int soDH)
        {
            int para = 1;
            string[] name = new string[para];
            object[] value = new object[para];
            name[0] = "@soDH";
            value[0] = soDH;
            return cn.UpdateTableStore("sp_donhang_delete", name, value, para);
        }

        
    }

}
